package com.market.bean.common;

import com.github.pagehelper.PageInfo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * @author stone
 * @date 2022/04/06 10:13
 */
@NoArgsConstructor
@Data
@AllArgsConstructor
public class CommonData<T> {

    /*limit: 20
    list: [{id: 1152101, goodsSn: "1152101", name: "魔兽世界 部落 奥格瑞玛 拉杆箱 可登机", categoryId: 1012001, brandId: 0,…},…]
    page: 6
    pages: 13
    total: 241*/
    private Integer total;
    private Integer pages;
    private Integer limit;
    private Integer page;
    private List<T> list;



    // public static <T> CommonData<T> data(PageInfo<T> pageInfo) {
    //     int pageNum = pageInfo.getPageNum(); //page
    //     int pageSize = pageInfo.getPageSize();//limit
    //     int pages = pageInfo.getPages();//pages
    //     long total = pageInfo.getTotal();
    //     List<T> list = pageInfo.getList();
    //     // CommonData<MarketUser> data =
    //     return new CommonData<T>((int) total, pages, pageSize, pageNum, list);
//
    //分页查询的数据
    public static <T> CommonData<T> data(PageInfo<T> pageInfo) {
        long total = pageInfo.getTotal();        //查询的总数据量
        int pages = pageInfo.getPages();         //总页数 pages
        int pageNum = pageInfo.getPageNum();     //第几页数 page
        int pageSize = pageInfo.getPageSize();   //单页显示的数据量 limit
        List<T> list = pageInfo.getList();       //分页查询到的数据
        CommonData<T> data = new CommonData<T>((int) total, pages, pageSize, pageNum, list);
        return data;
    }
}
